package com.zhl.service.impl;

import com.zhl.dao.UserDao;
import com.zhl.entity.User;
import com.zhl.service.UserService;
import com.zhl.utils.TransactionManager;

import java.util.List;

/**
 * 业务实现层
 *
 *
 * 控制事务
 */
public class UserServiceImpl2 implements UserService {
    private UserDao userDao;
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
    @Override
    public List<User> findAllUser() {
            return userDao.findAllUser();
    }

    @Override
    public User findOne(Integer id) {
            return userDao.findOne(id);
    }

    @Override
    public void addUser(User user) {
            userDao.addUser(user);
    }

    @Override
    public void deleteUser(Integer id) {
            userDao.deleteUser(id);
    }

    @Override
    public void updateUser(User user) {

            userDao.updateUser(user);
    }

    @Override
    public void transferUser(String sourceName, String targetName, Double money) {

            User sourceUser = userDao.findUserByName(sourceName);
            User targetUser = userDao.findUserByName(targetName);

            sourceUser.setMoney(sourceUser.getMoney()-money);
            targetUser.setMoney(targetUser.getMoney()+money);
       // int i=1/0;
            userDao.updateUser(sourceUser);
            userDao.updateUser(targetUser);

    }

    @Override
    public void findUserByName(String userName) {
            userDao.findUserByName(userName);
    }
}
